package club.laowang.model.model1.chain;

import club.laowang.model.model1.handler.ILogicHandler;

public class BusinessLinkedList<T, D, R> extends LinkedList<ILogicHandler<T, D, R>> implements ILogicHandler<T, D, R>{
    public BusinessLinkedList(String name) {
        super(name);
    }

    @Override
    public R apply(T requestParameter, D dynamicContext) {
        LinkedList.Node<ILogicHandler<T, D, R>> current = this.first;
        do {
            ILogicHandler<T, D, R> handler = current.item;
            R apply = handler.apply(requestParameter, dynamicContext);
            if (apply != null) {
                return apply;
            }
            current = current.next;
        } while (current != null);

        return null;
    }
}
